Code sample Home

Create TIN object (Triangulated Irregular Network)

A drawing has TIN entity with Key=123. The sample code finds the entity, clear the TIN data and creates new TIN data. Also set the option to keep the TIN data in external file, not in the drawing file.

void DemoTinCreate2 (HANDLE hLcWnd)
{
  HANDLE hBlock, hTIN, hPtype;
  int    Color;
  WCHAR* szPtypeName = L"Default";  // name of point type
  WCHAR* szFileName;

  // get a block, linked with CAD window
  hBlock = lcPropGetHandle( hLcWnd, LC_PROP_WND_VIEWBLOCK );

  // find TIN entity
  hTIN = lcBlockGetEntByKey( hBlock, 123 );
  if (lcEntType( hTIN, LC_ENT_TIN )){
    // clear TIN data
    if (lcTIN_Clear(hTIN)){
      // define TIN points
      lcTIN_AddPoint( hTIN, szPtypeName, 0, 0, 101.7 );
      lcTIN_AddPoint( hTIN, szPtypeName, 0, 25, 103.3 );
      lcTIN_AddPoint( hTIN, szPtypeName, 0, 50, 103.0 );
      lcTIN_AddPoint( hTIN, szPtypeName, 25, 0, 102.5 );
      lcTIN_AddPoint( hTIN, szPtypeName, 25, 25, 103.8 );
      lcTIN_AddPoint( hTIN, szPtypeName, 25, 50, 102.2 );
      lcTIN_AddPoint( hTIN, szPtypeName, 50, 0, 103.8 );
      lcTIN_AddPoint( hTIN, szPtypeName, 50, 25, 104.1 );
      lcTIN_AddPoint( hTIN, szPtypeName, 50, 50, 105.0 );
      // generate boundary
      if (lcTIN_Bnd( hTIN, 0.0, hLcWnd )){
        // triangilate points inside boundary
        if (lcTIN_Triangulate( hTIN, hLcWnd )){
          // generate isolines
          lcTIN_Isolines( hTIN, 0.2, 5, hLcWnd );
          // generate color filling
          lcTIN_ColorFill( hTIN, 0.2, 0.05, hLcWnd );
          // set visibility of TIN elements
          lcPropPutBool( hTIN, LC_PROP_TIN_VIEWPT, true );    // point
          lcPropPutBool( hTIN, LC_PROP_TIN_VIEWPTN, false );  // point name
          lcPropPutBool( hTIN, LC_PROP_TIN_VIEWPTI, false );  // point index
          lcPropPutBool( hTIN, LC_PROP_TIN_VIEWPTZ, true );   // point Z
          lcPropPutBool( hTIN, LC_PROP_TIN_VIEWBND, false );  // boundary
          lcPropPutBool( hTIN, LC_PROP_TIN_VIEWCF, true );    // color filling
          lcPropPutBool( hTIN, LC_PROP_TIN_VIEWISO, true );   // isolines
          lcPropPutBool( hTIN, LC_PROP_TIN_VIEWISOH, true );  // heights of isolines
          // set parameters for point type
          hPtype = lcTIN_PtypeGetByName( hTIN, szPtypeName );
          if (hPtype != 0){
            lcPropPutStr( hPtype, LC_PROP_TINPTYPE_DTEXT, L"STD" );
            Color = lcColorRGB( 255, 0, 0 );
            lcPropPutInt( hPtype, LC_PROP_TINPTYPE_COLOR, Color );
          }
        }
      }
      lcBlockUpdate( hBlock, false, 0 );   // update extents 
      lcWndZoomRect( hLcWnd, 0,0,0,0 );
      lcWndZoomScale( hLcWnd, 0.8 );

      // store TIN data in external file
      szFileName = L"c:/!OK/Data/TIN/Sample001.tin";
      lcPropPutStr( hTIN, LC_PROP_TIN_FILENAME, szFileName );
      lcPropPutBool( hTIN, LC_PROP_TIN_EXTERNAL, true );
    }
  }
}

This will create a drawing as shown on the picture below:



Without color filling: